package com.laixu.estore.web.exception;

import com.laixu.estore.web.response.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Auther: vanse(lc)
 * @Date: 2025/3/14-03-14-12:05
 * @Description：com.briup.estore.web.exception
 */
@RestControllerAdvice // 异常处理器
// advice aop 前置通知 后置通知
public class GlobalExceptionoHandler {
    // 如果有异常，就会捕获 响应
    @ExceptionHandler(BookStoreException.class)
    public Result bookException(BookStoreException be){
        be.printStackTrace();
        return Result.error(be.getCode(),be.getMsg());
    }

    // 其他异常
    @ExceptionHandler(Exception.class)
    public Result systemException(Exception e){
        e.printStackTrace();
        return Result.error(BookStoreException.CodeMsgEnum.ERROR);
    }
}
